import cv2
import numpy as np
import time
from utils import capture_screenshot, check_color
from settings import sleep_options

def get_gold_index(image=None):
    time.sleep(sleep_options["开包截图"])
    package_count = 5  # 只需修改这个数字即可调整检查的包数量
    gold_package_indices = []

    # 循环数字而不是具体的包名称列表
    for i in range(1, package_count + 1):
        # 动态生成包名称，如"第1个包"、"第2个包"
        package_name = f"第{i}个包"
        is_money = check_color(package_name, (253, 230, 100))
        if is_money:
            gold_package_indices.append(i)  # 直接使用循环的数字作为索引

    return gold_package_indices

def get_is_win(image=None):
    """
    判断是否自摸胡牌
    """
    if image is None:
        image = capture_screenshot(region_name="和了", delay=sleep_options["读牌截图"])
    average_color = np.mean(image, axis=(0, 1))
#     print(average_color)
    # 定义每种颜色的参考值和误差范围
    win_color = np.array([50.68, 21.52, 108.38])
    error_margin = 10  # 误差余量

    if np.all(np.abs(average_color - win_color) <= error_margin):
        return True
    return False

if __name__ == "__main__":
#     test_save_path = "images/package/test_package1.png"
#     image = cv2.imread(test_save_path)
    is_win = get_gold_index()
    print(is_win)
